﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LTM_Extra;

namespace LTM_Main
{
    public partial class ManagingSettings : Form
    {
        public ManagingSettings()
        {
            InitializeComponent();
        }
        ContentProvider contentProvider = new ContentProvider();

        private void ManagingSettings_Load(object sender, EventArgs e)
        {
            try
            {
                var authorList = contentProvider.GetAuthorList();
                var defaultAuthor = contentProvider.GetAppSettings(Constants.DefaultAuthorKey);
                cmbDefaultAuthor.DataSource = authorList;
                cmbDefaultAuthor.SelectedIndex = authorList.IndexOf(defaultAuthor);

                lblPath.Text = contentProvider.GetAppSettings(Constants.TemplateFolderKey);
                lblVersionNumber.Text = contentProvider.GetAppSettings(Constants.VersionNumberKey);
                lblInstallInfo.Text = contentProvider.GetAppSettings(Constants.InstallInfoKey);
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                contentProvider.SetDefaultAuthor(cmbDefaultAuthor.SelectedItem.ToString());
                contentProvider.SaveAppSetting();
                Close();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            try
            {
                folderBrowserDialog.ShowDialog();
                lblPath.Text = folderBrowserDialog.SelectedPath;
                contentProvider.SetTemplateFolderPath(folderBrowserDialog.SelectedPath);
                if (!contentProvider.TemplateFolderIsConfigured())
                {

                    MessageBox.Show("Please select the right template folder.");

                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }

        }
    }
}
